#include "aky_program/aky_com_include.h"
static void my_event_cb(lv_obj_t * obj, lv_event_t event);

static uint16_t time_cnt = 0;
// static wav_obj_t* wav_1;
static lv_obj_t *img_start_screen;          //
static uint8_t flag_first_up_voice = 0;

/*
 * 界面回调函数
 */
static void screen001_on_timer(void *user_data)
{
    /* 界面定时器回调函数 */
    static uint16_t fil_cnt = 0;

    if (flag_first_up_voice == 0)
    {
        fil_cnt++;
        if (fil_cnt > 20)
        {
            fil_cnt = 0;
            flag_first_up_voice = 1;
            voice_play_single(START_UP);
        }
    }

    time_cnt++;
    if (time_cnt > 3000 / 10)
    {
        time_cnt = 0;
#if 00
        synwit_ui_load_screen(SCREEN_TEST2);

#else
        synwit_ui_load_screen(SCREEN002);

#endif
    }
    screen_flush_pro();

}

static void screen001_start(synwit_id_t screen_id)
{
    /* 在界面被显示给用户前，这个接口会被调用。 */
    static uint8_t flag_first_up = 0;
    time_cnt = 0;
    flag_first_up_voice = 0;
    // wav_1 = synwit_wav_open("S:spi:voice/voice_1.wav");
    // synwit_wav_play(wav_1,LV_TASK_PRIO_HIGH);
    // aky_voice_table_play(START_UP);
#if 00
            synwit_ui_load_screen(SCREEN_TEST);
            return;
#endif

    if (flag_first_up == 0)
    {
        flag_first_up = 1;
        if (get_cur_charge_stat() != NO_CHARGE)
        {
            synwit_ui_load_screen(SCREEN013);
            return;
        }
    }


    img_start_screen = synwit_ui_find_lv_obj(WIDGET_IMAGE2);
    lv_obj_set_click(img_start_screen, true);
    lv_obj_set_event_cb(img_start_screen, my_event_cb);   /*Assign an event callback*/

    // 打开下面的注释可以为本界面开启一个每100ms触发一次的定时器
    screen_init();
    synwit_ui_start_scr_timer(10, NULL);
    
    
#if 00
    lv_obj_t* avi_test = lv_avi_create(lv_scr_act(), NULL);
    if (lv_avi_set_src(avi_test, "S:sd:video_1.avi") == 0)
    {
        // lv_avi_play(avi_test);
        stat_bar_stop_flush();
        // lv_avi_set_on_completed_cb(avi_test,my_avi_complete_cb, NULL);
    }
#endif
}

static void screen001_stop(synwit_id_t screen_id)
{
    /* 准备切换到其它界面前，这个接口会被调用。 */
	voice_stop();
    // synwit_wav_stop(wav_1);
    screen_stop();

}
static int screen001_favorite_stop_policy()
{
    /* 函数返回值表示本界面结束时，希望采用的资源管理策略 */

    /* 资源管理策略(主要影响本界面再次进入时的加载速度):
     *    0: 系统推荐，释放当前界面引用的资源，保留控件及控件状态。可获得平衡的界面切换性能和内存消耗
     *    1: 释放当前界面引用的资源，并删除所有控件。
     *    2: 保留当前界面的所有资源及控件。可以获得最佳的界面切换性能，但内存消耗较大
     */
    return 0;
}


/*
 * 界面注册对象
 */
synwit_screen_callback_t screen001_cb_obj = {
    .favorite_stop_policy = screen001_favorite_stop_policy,
    .on_screen_start = screen001_start,
    .on_screen_stop = screen001_stop,
    .on_screen_timer = screen001_on_timer,
};

static void my_event_cb(lv_obj_t * obj, lv_event_t event)
{
    off_time_clr();
    if (obj == img_start_screen)
    {
        if (event == LV_EVENT_CLICKED)
        {
        	voice_stop();
            synwit_ui_load_screen(SCREEN002);
        }
    }
}